<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

/**
 * App\Models\ConfigSale
 *
 * @property int $id
 * @property int $is_bonus_enable every day bonus distributing
 * @property int $is_brokerage_enable every month brokerage distributing
 * @property string $vip_price price of a vip account
 * @property int|null $vip_period buy vip account for 30 days
 * @property int $auto_upgrade_needs_children
 * @property string $give_bonus_started_at
 * @property string $give_bonus_ended_at
 * @property string $bonus_into_account_percent
 * @property string $bonus_into_spend_percent
 * @property int|null $protected_bonus_level user can always get everyday bonus at this bonus_level=grade_level
 * @property int|null $obtain_children_bonus_levels_by_multiple my bonus_level * this multiple can go into formal after exam
 * @property int|null $most_obtain_children_bonus_levels_by_my_bonus_level_multiple my bonus_level * this multiple is my final bonus_level
 * @property string $product_brokerage_percent all brokerage from one product
 * @property array|null $product_brokerage give brokerage to up star parents after buying product
 * @method static \Database\Factories\ConfigSaleFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale query()
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereAutoUpgradeNeedsChildren($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereBonusIntoAccountPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereBonusIntoSpendPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereGiveBonusEndedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereGiveBonusStartedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereIsBonusEnable($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereIsBrokerageEnable($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereMostObtainChildrenBonusLevelsByMyBonusLevelMultiple($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereObtainChildrenBonusLevelsByMultiple($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereProductBrokerage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereProductBrokeragePercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereProductSelfBrokerage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereProtectedBonusLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereVipPeriod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereVipPrice($value)
 * @mixin \Eloquent
 * @property string $product_self_brokerage give brokerage to self after buying product
 * @property int $vip_limit_start_number start limit vip orders after this number
 * @property string $vip_limit_exceed_last_day_percent if today's vip orders exceed yestoday this percent
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereVipLimitExceedLastDayPercent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereVipLimitStartNumber($value)
 * @property bool $is_bonus_being_divided
 * @method static \Illuminate\Database\Eloquent\Builder|ConfigSale whereIsBonusBeingDivided($value)
 */
class ConfigSale extends Model
{
    use HasFactory;
	
	protected $guarded = ['id'];
	
	public $timestamps = false;
	
	protected $casts = [
	];
	
	public function getProductBrokerageAttribute($value)
	{
		return array_values(json_decode($value, true) ?: []);
	}
	
	public function setProductBrokerageAttribute($value)
	{
		$this->attributes['product_brokerage'] = json_encode(array_values($value));
	}
}
